package com.kou.controller;/**
 * @author SteinY
 * @create 2022-03-24 21:32
 * @description:
 */

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * projectName:myshop2
 * author:SteinY
 * time:2022/3/24 21:32
 * description:
 */
@WebServlet("/code")
public class CodeServlet extends BaseServlet {
    public void createCode(HttpServletRequest request, HttpServletResponse response){
        response.setContentType("image/jpeg");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0L);

        HttpSession session = request.getSession();
        //codeCount = 4位数
        ValidateCode vCode = new ValidateCode(111, 36, 4, 0);
        System.out.println(vCode.getCode());
        session.setAttribute("code", vCode.getCode());

        //响应流 输出出去
        try {
            vCode.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}